package com.csleasing.user.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

@RestController
public class UserController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("user")
    public Object user(){
    	logger.info("用户查询中!");
    	Object body = "";
		try {
			//int  result = 1/0;
			ResponseEntity<String> mainOrderResponseEntity = restTemplate.getForEntity("http://localhost:8082/prod", String.class);
			body = mainOrderResponseEntity.getBody();
		} catch (Exception e) {
			logger.error("This is error message.",e);
		}
        return body;
    }
    
    @RequestMapping("test")
    public Object test(){
    	logger.info("用户服务测试!");
        return "test";
    }
    @RequestMapping("test2")
    public Object test2(){
    	logger.info("用户服务异常测试!");
    	try {
			int  result = 1/0;
		} catch (Exception e) {
			logger.error("This is error message.",e);
		}
        return "test2";
    }
    
    @RequestMapping("test3")
    public Object test3(){
    	logger.info("用户服务异常测试!");
    	try {
    		int  result = 1/0;
		} catch (Exception e) {
			e.printStackTrace();
		}
        return "test3";
    }
    
    @RequestMapping("test4")
    public Object test4(){
    	logger.info("用户服务异常测试!");
    	int  result = 1/0;
        return "test4";
    }
}
